package cn.edu.cdut.handler;

import cn.edu.cdut.dto.MyRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author  kobe
 * Created on 2017-06-21-19:21
 */
//此注解表示：此类为controller协助类
@ControllerAdvice
class MyExceptionHandler {
        //日志
        private final static Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);

        //此注解绑定异常与处理方法
        @ExceptionHandler(value = Exception.class)//指示要处理的异常
        @ResponseBody
        public MyRes myHandle(Exception e) {
                logger.error("【系统异常】:", e);
                return new MyRes(500, "未知错误", null);
        }
}
